package com.ivy.irublesson.utils;

import android.util.Log;

import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;

/**
 * Created by Administrator on 2018/1/16.
 */

public class Cookie {
    public static String getImgData(){
        String path = "http://1.85.55.152/ZNPK/Private/List_JS.aspx?xnxq=20170&js=";
        String cookie = "ASP.NET_SessionId=5nwpkxjdtt0omjjoly0nsjeb";
        String referer = "http://1.85.55.152/ZNPK/TeacherKBFB.aspx";
        String params = " ";

        try {

            URL url=new URL(path);
            HttpURLConnection con=(HttpURLConnection)url.openConnection();
            con.setRequestMethod("GET");
            con.setDoOutput(true);
            con.setDoInput(true);
            con.setRequestProperty("Referer", referer);
            InputStream in=con.getInputStream();
            cookie = con.getHeaderField("Set-Cookie");
            Log.i("Cookie........" , cookie);

//            stream = new ByteArrayOutputStream();
//            int len = 0;
//            byte[] buffer = new byte[1024];
//            while((len=in.read(buffer))!=-1){
//                stream.write(buffer, 0, len);
//            }

            in.close();
            con.disconnect();

            return cookie;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }

    }

}
